<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="24">
					<el-form-item label="出库标题" prop="title">
						<el-input v-model="form.title" placeholder="出库标题" maxlength="180" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="档案编号" prop="archivesId">
						<el-select v-model="form.archivesId" clearable filterable remote :remote-method="remoteMethod" style="width: 100%" placeholder="输入档案编号或地址查询">
							<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="出库类型" prop="outboundType">
						<sc-select v-model="form.outboundType" :params="{code:'outboundType'}" :apiObj="$API.archives.archivesDic.getArchivesDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="出库时间" prop="outboundTime">
						<el-date-picker v-model="form.outboundTime" placeholder="出库时间" type="datetime" value-format="YYYY-MM-DD HH:mm" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="出库姓名" prop="outboundUser">
						<select-user-dialog v-model:accountId="form.outboundUser" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明" prop="remark">
				<el-input type="textarea" v-model="form.remark" placeholder="备注说明" maxlength="380" clearable></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog.vue";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			titleMap: {
				add: '档案出库登记',
				edit: '档案出库登记',
			},
			fileList:[],
			options:[],
			form: {
				recordId:'',
				archivesId: '',
				title:'',
				outboundType: '',
				outboundTime: '',
				outboundUser:'',
				remark: '',
			},
			rules: {
				archivesId: [
					{required: true, message: '档案编号不能为空', trigger: 'blur'}
				],
				title: [
					{required: true, message: '出库标题不能为空', trigger: 'blur'}
				],
				outboundType:[
					{required: true, message: '出库类型不能为空', trigger: 'blur'}
				],
				outboundTime:[
					{required: true, message: '出库时间不能为空', trigger: 'blur'}
				],
				outboundUser:[
					{required: true, message: '出库人员不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
		this.remoteMethod("")
	},
	methods: {
		async remoteMethod(query){
			let res = await this.$API.archives.archivesRecord.getArchivesRecordListForSelect.get({keyword:query});
			if (res.code == 200) {
				this.options = res.data
			}
		},
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.archives.archivesOutbound.insertArchivesOutbound.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.archives.archivesOutbound.updateArchivesOutbound.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.archivesId = data.archivesId
			this.form.title = data.title
			this.form.outboundType = data.outboundType
			this.form.outboundTime =data.outboundTime
			this.form.outboundUser = data.outboundUser
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
